// ==UserScript==
// @name        s1-黄科毕业考试快速办理脚本
// @namespace   通过学号或姓名批量查询出通过的学生并一键处理
// @match       http://58.51.106.70:9102/leaschool/*
// @match       http://172.18.254.15:8080/leaschool/*
// @match       https://xg.hbhgkj.edu.cn/leaschool/*
// @grant       none
// @downloadUrl  https://gitee.com/drunkenanimal/js-plug-in/raw/master/s1-黄科毕业考试快速办理脚本.user.js
// @version     1.7
// @author      陈沧
// @description 2024/7/1
// ==/UserScript==





//触发
 function handleFiles(files)
{
  if(files.length){
    let file = files[0];
    let reader = new FileReader();
    reader.onload = function(){
      aInnerText=this.result.split('\n');
      shaiXuan();
    }
    reader.readAsText(file);
   }
}

 function handleFiles2(files)
{
  if(files.length){
    let file = files[0];
    let reader = new FileReader();
    reader.onload = function(){
      aInnerText=this.result.split('\n');
      shaiXuan2();
    }
    reader.readAsText(file);
   }
}


//查询内容筛选
function shaiXuan(){
	var oDiv=document.getElementsByTagName('tbody')[0].getElementsByTagName('tr');
  document.getElementsByTagName('thead')[0].getElementsByTagName('tr')[0].getElementsByTagName('th')[1].getElementsByTagName('input')[0].setAttribute('disabled',true);
	for(j=0;j<oDiv.length;j++){
		var flag='0';
		for(i=0;i<aInnerText.length;i++){
			if(oDiv[j].getElementsByTagName('td')[2].innerHTML==aInnerText[i].toString().replace(/[\r\n]/g,"")){
        flag="1";
				continue;
			}
		}
		if(flag =='0'){
			oDiv[j].style.display='none';
		}else {
      oDiv[j].getElementsByTagName('td')[1].getElementsByTagName('div')[0].className += ' checked';
      oDiv[j].getElementsByTagName('td')[1].getElementsByTagName('div')[0].setAttribute('aria-checked',true);
      oDiv[j].getElementsByTagName('td')[1].getElementsByTagName('div')[0].getElementsByTagName('input')[0].setAttribute('checked','checked');
    }
	}
}

function shaiXuan2(){
	var oDiv=document.getElementsByTagName('tbody')[0].getElementsByTagName('tr');
  document.getElementsByTagName('thead')[0].getElementsByTagName('tr')[0].getElementsByTagName('th')[1].getElementsByTagName('input')[0].setAttribute('disabled',true);
	for(j=0;j<oDiv.length;j++){
		var flag='0';
		for(i=0;i<aInnerText.length;i++){
			if(oDiv[j].getElementsByTagName('td')[3].innerHTML==aInnerText[i].toString().replace(/[\r\n]/g,"")){
        flag="1";
				continue;
			}
		}
		if(flag =='0'){
			oDiv[j].style.display='none';
		}else {
      oDiv[j].getElementsByTagName('td')[1].getElementsByTagName('div')[0].className += ' checked';
      oDiv[j].getElementsByTagName('td')[1].getElementsByTagName('div')[0].setAttribute('aria-checked',true);
      oDiv[j].getElementsByTagName('td')[1].getElementsByTagName('div')[0].getElementsByTagName('input')[0].setAttribute('checked','checked');
    }
	}
}


function showMore(){
  var oSel=document.getElementsByTagName('select')[4];
  oSel.options.add(new Option('1000',1000));
  alert('添加选项成功!');
}

window.onload=function(){
  var aInnerText=[];
//添加功能按钮
  var oBt=document.createElement('input');
	oBt.setAttribute('type','button');
	oBt.setAttribute('value','增加每页显示1000选项');
  document.body.appendChild(oBt);
  oBt.onclick=function(){
    showMore();
  }
//添加上传文件控件
  var newDiv = document.createElement('div');
  newDiv.innerHTML = '按学号查询';
  document.body.appendChild(newDiv);
	var oInput=document.createElement('input');
	oInput.setAttribute('type','file');
	oInput.setAttribute('id','file');
	document.body.appendChild(oInput);

  var newDiv2 = document.createElement('div');
  newDiv2.innerHTML = '按姓名查询';
  document.body.appendChild(newDiv2);
	var oInput2=document.createElement('input');
	oInput2.setAttribute('type','file');
	oInput2.setAttribute('id','file');
	document.body.appendChild(oInput2);

  oInput.onchange=function(){
    handleFiles(this.files);
  }

  oInput2.onchange=function(){
    handleFiles2(this.files);
  }
}





